<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<body>
<div id="d1">
 <h1>计算属性</h1> {{birth}}
  <input type="text" v-model="message">
</div>


<script>
  const vm = new Vue({
    el: "#d1",
    data: {
      birthday: 1429032123201,
      // 毫秒值
      message:""
    },
    computed:{
      birth(){//计算属性本质是一个方法，但是必须返回结果
        let d = new Date(this.birthday);
        let year=d.getFullYear();
        let month=d.getMonth()+1;
        let day=d.getDate();
        return year + "-" + month + "-" + day;
      }
    },
    watch:{
      message(newVal, oldVal){
        console.log(newVal, oldVal);
      }
    }
  });
</script>
</body>
</html>
